﻿#region
/*******************************************************************************
** File Name:		    FoodSetService.cs
** Creator:		        chao.jiang 
** EMail:               chao.jiang 
** Create date:	        
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using EWineShop.Service.Contracts;
using EWineShop.Service.Model;
using EWineShop.IBatisRepository;
using EWineShop.Respository;
using System.Data;
using EWineShop.Entity;

namespace EWineShop.Service
{
    public class FoodSetService : IFoodSetService
    {
		 IFoodSet foodSet = new FoodSetRepository();
		 
		 #region  Auto Generation
		 

		public void UpdateByFoodSetID (FoodSetModel model)
		{
			EFoodSet entity = ConvertModelToEntity(model);

            foodSet.UpdateByFoodSetID(entity);

		}

		public void DeleteByFoodSetID (System.Int64 foodSetID)
		{
		
            foodSet.DeleteByFoodSetID(foodSetID);

		}
		 
        public FoodSetModel GetByFoodSetID (System.Int64 foodSetID)
        {
        
			EFoodSet entity = foodSet.GetByFoodSetID(foodSetID);
			
            FoodSetModel model = ConvertEntityToModel(entity);


            return model;
        }
        
	
		public IList<FoodSetModel> GetAll ()
		{
			IList<EFoodSet> entity = foodSet.GetAll();
			
			if (entity == null)
            {
                return null;
            }
            
            IList<FoodSetModel> list = new List<FoodSetModel>();

            foreach (var item in entity)
            {
                FoodSetModel model = ConvertEntityToModel(item);
                list.Add(model);
            }
            return list;   
			
		}
		
		private FoodSetModel ConvertEntityToModel(EFoodSet entity)
		{
			if (entity == null)
            {
                return null;
            }
			FoodSetModel model = new FoodSetModel();
                        model.FoodSetID = entity.FoodSetID;
                        model.Code = entity.Code;
                        model.Name = entity.Name;
                        model.Price = entity.Price;
                        model.CreateTime = entity.CreateTime;
                        model.UpdateTime = entity.UpdateTime;
                        return model;
		}
		
		private EFoodSet ConvertModelToEntity(FoodSetModel model)
		{
			if (model == null)
            {
                return null;
            }
			EFoodSet entity = new EFoodSet();
                        entity.FoodSetID = model.FoodSetID;
                        entity.Code = model.Code;
                        entity.Name = model.Name;
                        entity.Price = model.Price;
                        entity.CreateTime = model.CreateTime;
                        entity.UpdateTime = model.UpdateTime;
                        return entity;
		}
		
		
		
		#endregion
    }
}